﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static Dictionary<string, string> User = new Dictionary<string, string>();

        private void button1_Click(object sender, EventArgs e)
        {


            if (string.IsNullOrEmpty(textBox1.Text) && string.IsNullOrEmpty(textBox2.Text))//都为空时
            {
                timer1.Enabled = true;
                label5.Text = "用户名不能为空";
                label6.Text = "密码不能为空";
                textBox1.Focus();
            }
            else if (string.IsNullOrEmpty(textBox1.Text))//用户名为空时
            {
                timer1.Enabled = true;
                label5.Text = "用户名不能为空";
                textBox1.Focus();
            }
            else if (string.IsNullOrEmpty(textBox2.Text))//密码为空时
            {
                timer1.Enabled = true;
                label6.Text = "密码不能为空";
                textBox2.Focus();
            }
            else
            {
                if (User.ContainsKey(textBox1.Text) && User[textBox1.Text].Equals(textBox2.Text))
                {
                    MessageBox.Show("登录成功！", "登录");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("用户名或密码不正确！\n请重新输入", "登录");
                    textBox1.SelectAll();//全选text1内容
                    textBox1.Focus();//text1获取焦点
                    textBox2.Text = null;

                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var gb = MessageBox.Show("是否退出程序！", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (gb == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            textBox1.Focus();

        }

        private void textBox2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                timer1.Enabled = true;
                label5.Text = "用户名不能为空";

            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label5.Text = null;
            label6.Text = null;
        }

        private void label3_MouseEnter(object sender, EventArgs e)
        {
            label3.ForeColor = System.Drawing.Color.Red;
        }

        private void label3_MouseLeave(object sender, EventArgs e)
        {
            label3.ForeColor = System.Drawing.Color.Silver;
        }

        private void label8_MouseEnter(object sender, EventArgs e)
        {
            label8.ForeColor = System.Drawing.Color.Red;
        }

        private void label8_MouseLeave(object sender, EventArgs e)
        {
            label8.ForeColor = System.Drawing.Color.Silver;
        }

        private void label3_Click(object sender, EventArgs e)//跳转忘记密码，功能还未完善
        {
            //this.Visible = false;
            //Form2 form2 = new Form2();
            //form2.ShowDialog();
            //this.Visible = true;
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox1.Text) && string.IsNullOrEmpty(textBox2.Text))
            {
                timer1.Enabled = true;
                label6.Text = "密码不能为空";
            }
        }

        private void label8_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            Form3 form3 = new Form3();
            form3.ShowDialog();
            this.Visible = true;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            User.Add("admin", "123456");
            User.Add("aa", "147852");
        }


    }
}
